package com.medical.data.controller;

import com.medical.data.domain.FormTemplate;
import com.medical.data.service.FormTemplateService;
import com.medical.data.service.ProjectTemplateService;
import com.medical.data.utils.Result;
import com.medical.data.vo.NodeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/front/node")
@Api(description = "节点管理(父模版)")
@Slf4j
public class FormTemplateController {
    @Autowired
    FormTemplateService formTemplateService;

    @Autowired
    ProjectTemplateService projectTemplateService;

    @ApiImplicitParam(name = "nodeVo", required = true, paramType = "body", dataTypeClass = NodeVo.class)
    @ApiOperation("创建节点,就是创建父模版,传随访间隔就是创建随访节点")
    @PostMapping("/createNode")
    public Result createNode(@Validated @RequestBody NodeVo nodeVo) {
        log.info("/front/node/createNode参数========>{}", nodeVo);
        formTemplateService.createNode(nodeVo);
        return Result.ok();
    }

    @ApiImplicitParam(name = "nodeVo", required = true, paramType = "body", dataTypeClass = NodeVo.class)
    @ApiOperation("删除节点")
    @PostMapping("/deleteNode/{nodeId}")
    public Result deleteNode(@PathVariable String nodeId) {
        log.info("/front/node/getNode参数========>{}", nodeId);
        formTemplateService.deleteNode(nodeId);
        return Result.ok();
    }


    @ApiImplicitParam(name = "nodeVo", required = true, paramType = "body", dataTypeClass = NodeVo.class)
    @ApiOperation("获取非随访节点")
    @PostMapping("/getNode/{projectId}")
    public Result getNode(@PathVariable String projectId) {
        log.info("/front/node/getNode参数========>{}", projectId);
        List<FormTemplate> formTemplates = projectTemplateService.getNodesByProjectId(projectId);
        return Result.ok().data("formTemplate", formTemplates);
    }

    @ApiImplicitParam(name = "nodeVo", required = true, paramType = "body", dataTypeClass = NodeVo.class)
    @ApiOperation("获取随访节点")
    @PostMapping("/getFollowNode/{projectId}")
    public Result getFollowNode(@PathVariable String projectId) {
        log.info("/front/node/getFollowNode参数========>{}", projectId);
        List<FormTemplate> formTemplates = projectTemplateService.getFollowNodesByProjectId(projectId);
        return Result.ok().data("formTemplate", formTemplates);
    }

}
